﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace WPF_DbCenter.SqlServer.DataExchange
{
    /// <summary>
    /// Interaction logic for SrcTableList.xaml
    /// </summary>
    public partial class SrcTableList : Page
    {
        CoreEA.ICoreEAHander core;
        public SrcTableList(CoreEA.ICoreEAHander inCore)
        {
            core = inCore;
            InitializeComponent();

        }

        /// <summary>
        /// Background thread
        /// </summary>
        private void LoadDbInfo()
        {
            BackgroundWorker bg = new BackgroundWorker();
            this.listBox1.Items.Clear();
            bg.WorkerReportsProgress = true;
            bg.DoWork += delegate(object s1, DoWorkEventArgs se)
            {
                List<string> dbList = core.GetDatabaseList();

                foreach (string item in dbList)
                {
                    bg.ReportProgress(0,item);
                }

            };

            bg.ProgressChanged += delegate(object s2, ProgressChangedEventArgs args)
            {
                listBox1.Items.Add(args.UserState.ToString());
            };

            bg.RunWorkerAsync();
        }

        private void butNext_Click(object sender, RoutedEventArgs e)
        {
            if (this.listBox1.SelectedItems == null)
            {
                return;
            }
            List<string> tableList = new List<string>();
            foreach (string item in listBox1.SelectedItems)
            {
                tableList.Add(item);
            }

            TargetServer ts = new TargetServer(core, tableList);
            this.NavigationService.Navigate(ts);


        }
    }
}
